package logic

import (
	"context"
	"github.com/olivere/elastic/v7"
	"project/weeksrv/service/es"

	"project/weeksrv/internal/svc"
	"project/weeksrv/weeksrv"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetEsSearchByNameLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetEsSearchByNameLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetEsSearchByNameLogic {
	return &GetEsSearchByNameLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// es名称查询
func (l *GetEsSearchByNameLogic) GetEsSearchByName(in *weeksrv.GetEsSearchByNameReq) (*weeksrv.GetEsSearchByNameRes, error) {
	// todo: add your logic here and delete this line
	query := elastic.NewMatchAllQuery()
	goodsList, err := es.GetGoodsEsSearchByName(query)
	if err != nil {
		return nil, err
	}
	return &weeksrv.GetEsSearchByNameRes{
		Goods: goodsList,
	}, nil
}
